package cms.simmytech.util;

import java.util.HashMap;

import cms.simmytech.response.OrderExpressResponse;
import com.google.gson.Gson;

public class ExpressUtil {

	public static void main(String[] args) throws Exception {

		// String param = "{\"com\":\"shunfeng\",\"num\":\"256043173045\"}";
		// String customer = "8A56D713ACF208FED879A550A1EA6494";
		// String key = "nvMgkyOB2571";
		// System.out.println(param + key + customer);
		// String sign = MD5.md5EncodeUpper(param + key + customer);
		// System.out.println(sign);
		// HashMap<String, String> params = new HashMap<String, String>();
		// params.put("param", param);
		// params.put("sign", sign);
		// params.put("customer", customer);
		// String resp;
		// try {
		// resp = HttpUtil.post(params,
		// "http://poll.kuaidi100.com/poll/query.do");
		// System.out.println(resp);
		// }
		// catch (Exception e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		Gson gson = new Gson();
		OrderExpressResponse.OrderExpress orderExpress = gson.fromJson(queryExpress("shunfeng", "256043173045"), OrderExpressResponse.OrderExpress.class);
		System.out.println(gson.toJson(orderExpress));
	}

	public static String queryExpress(String com, String num) {
		String param = "{\"com\":\"" + com + "\",\"num\":\"" + num + "\"}";
		String sign = MD5.md5EncodeUpper(param + Constants.EXPRESS_KEY + Constants.EXPRESS_CUSTOMER);
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("param", param);
		params.put("sign", sign);
		params.put("customer", Constants.EXPRESS_CUSTOMER);
		String resp = null;
		try {
			resp = HttpUtils.post(params, Constants.EXPRESS_URL);
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return resp;
	}

}
